

/////////////////////////////下载相关

//暂停下载
function pauseDownload() {
}

//删除下载记录
function stopDownload() {
}

//取消下载
function cancelDownload() {
}

//恢复下载
function resumeDownload() {
}

//下载监听
function onCreated_addListener() {
}


///////////////////////////配置文件相关

//写入配置
function setConfig(config) {
    // set {"key1":"","key2":""}
    if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined') {
        chrome.storage.local.set(config);
    } else {
        Object.keys(config).forEach(function (key) {
            setCookie(key, config[key])
        });
    }
}


//读取配置
function getConfig(keys, back) {
    //set ["key1","key2"] get {"key1":"","key2":""}
    if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined') {
        chrome.storage.local.get(keys).then((result) => {
            back(result)
        });
    } else {
        var obj = {}
        keys.forEach(function (key) {
            obj[key] = getCookie(key);
        })
        back(obj)
    }
}


///////////////////////////浏览器监听相关


//上下文菜单点击监听
function contextMenus_onClicked() {

}

//安装运行时点击监听按钮
function onInstalled_addListener() {

}

//安装上下文菜单
function contextMenus_create() {

}


////////////////////////////UI相关

function setPopup() {

}

function openPopup() {

}


//获取当前插件版本
function getVersion(func) {
    if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined') {
        chrome.management.getSelf(
            (obj)=>{func(obj.version)}
        )
    } else {
        func("web")
    }
}


//浏览器打开tab页
function createTab(url){
    if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined') {
        chrome.tabs.create({url:url})
    } else {
        // location.href=url;
        window.open(url, "mozillaTab");
    }
}



/////////////////////////////

function setCookie(name, value) {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //正则匹配
    if (arr = document.cookie.match(reg)) {
        return unescape(arr[2]);
    } else {
        return null;
    }
}


function test() {
    console.log("///////////////woshiceshi///////////////////")
}
